<?php
// $Id: install.extcalendar.php,v 0.9 2005/05/18
//ExtCal Calendar//
// NOTICE: Portions of this install-file code were inspired by the code from 
// Events Calendar by Eric Lamette and Dave McDonnell and used a jumping-off
// point. Thank you to those excellent programmers! NOT the calendar, though; that was
// all by the ExtCal people.
/**
* Content code
* @package Mambo Open Source
* @ Mambo Open Source is Free Software
* @ Released under GNU/GPL License : http://www.gnu.org/copyleft/gpl.html
**/

// ################################################################
// MOS Intruder Alerts
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
// ################################################################

function com_install() {
global $database, $mosConfig_absolute_path, $mosConfig_mailfrom;

$database->setQuery( "SELECT id FROM #__components WHERE name= 'JCal Pro'" );
$id = $database->loadResult();

$database->setQuery( "UPDATE #__components SET admin_menu_img = '../components/com_jcalpro/images/calendar_icon_16x16.png' WHERE id = '$id'" );
$database->query();
//add new admin menu images
$database->setQuery( "UPDATE #__components SET admin_menu_img = 'js/ThemeOffice/config.png' WHERE parent='$id' AND name = 'Edit Settings'");
$database->query();
$database->setQuery( "UPDATE #__components SET admin_menu_img = 'js/ThemeOffice/categories.png' WHERE parent='$id' AND name = 'Manage Event Categories'");
$database->query();
$database->setQuery( "UPDATE #__components SET admin_menu_img = 'js/ThemeOffice/template.png' WHERE parent='$id' AND name = 'Manage Themes'");
$database->query();
$database->setQuery( "UPDATE #__components SET admin_menu_img = 'js/ThemeOffice/install.png' WHERE parent='$id' AND name = 'Install Themes'");
$database->query();
$database->setQuery( "UPDATE #__components SET admin_menu_img = 'js/ThemeOffice/backup.png' WHERE parent='$id' AND name = 'Import'");
$database->query();
$database->setQuery( "UPDATE #__components SET admin_menu_img = 'js/ThemeOffice/credits.png' WHERE parent='$id' AND name = 'About'");
$database->query();
$database->setQuery( "UPDATE #__components SET admin_menu_img = 'js/ThemeOffice/help.png' WHERE parent='$id' AND name = 'Documentation'");
$database->query();

//add new admin menu links

$database->setQuery( "UPDATE #__components SET admin_menu_link = 'option=com_jcalpro&task=install&element=themes' WHERE parent='$id' AND name = 'Install Themes'");
$database->query();

// Do the clean up if installed on a previous installation

$database->setQuery("SELECT count(id) as count, max(id) as lastInstalled FROM #__components WHERE name='ExtCal Calendar'");
$reginfo = $database->loadObjectList();
$lastInstalled = $reginfo[0]->lastInstalled;

// Check if there are more registered instances of the ExtCal Calendar component
if ($reginfo[0]->count <> "1") {
	// Get duplicates
	$sql="SELECT * FROM #__components WHERE name='ExtCal Calendar' AND id!='$lastInstalled' AND admin_menu_link LIKE 'option=com_jcalpro'";
	$database->setQuery($sql);
	$toberemoved = $database->loadObjectList();
	foreach ($toberemoved as $remid){
		// Delete duplicate entries
		$database->setQuery("DELETE FROM #__components WHERE id='$remid->id' or parent='$remid->id'");
		$database->query();
	}
}
$sql="UPDATE #__jcalpro_config SET value = '$mosConfig_mailfrom' WHERE name='calendar_admin_email'";
$database->setQuery($sql);
$database->query();

if (is_dir("../components/com_jcalpro/upload")) chmod("../components/com_jcalpro/upload",0777);
if (is_dir("../components/com_jcalpro/images/minipics")) chmod("../components/com_jcalpro/images/minipics",0777);

// Well done
    echo "Installed Successfully";
    echo "<div align='left'>";
    include ("../components/com_jcalpro/index.html");
    echo "</div>";
}

?>
